﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Threading;

namespace Mystery.SharePoint
{
	/// <summary>
	/// Changes the activate culture for a block of code
	/// </summary>
	public class CultureScope : IDisposable
	{
		private CultureInfo _currentCulture;
		private CultureInfo _currentUICulture;

		/// <summary>
		/// Constructs a new scope for culture
		/// </summary>
		/// <param name="culture">New culture to use</param>
		/// <param name="uiCulture">New UI culture to use</param>
		public CultureScope(CultureInfo culture, CultureInfo uiCulture)
		{
			// store current values
			_currentCulture = Thread.CurrentThread.CurrentCulture;
			_currentUICulture = Thread.CurrentThread.CurrentUICulture;

			// set new values
			Thread.CurrentThread.CurrentCulture = culture;
			Thread.CurrentThread.CurrentUICulture = uiCulture;
		}

		/// <summary>
		/// Reverts back to original culture
		/// </summary>
		public void Dispose()
		{
			Thread.CurrentThread.CurrentCulture = _currentCulture;
			Thread.CurrentThread.CurrentUICulture = _currentUICulture;
		}
	}
}
